<%@tag import="java.sql.Connection"%>
<%@tag import="by.epam.communalservices.utils.Login"%>

<%@ attribute name="object" required="true" type="by.epam.communalservices.entity.JkhObject"%>
<%@ attribute name="dif"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib tagdir="/WEB-INF/tags/connect" prefix="connect"%>
<%@ taglib tagdir="/WEB-INF/tags/object" prefix="object"%>
<%@ taglib tagdir="/WEB-INF/tags/table" prefix="table"%>
<%@ taglib tagdir="/WEB-INF/tags/user" prefix="user"%>

<connect:rule val="admin" rules="admin"/>
<connect:rule val="editor" rules="admin,object_edit,objecter" />
<connect:rule val="deletor" rules="admin,object_edit,edit" />

<c:choose>
	<c:when test="${editor}">
		<c:set var="link" value='"object_edit?id=${object.id}"' />
		<c:set var="click" value=" onclick='document.location.href=${link}' style='cursor:hand;'"  />
	</c:when>
	<c:otherwise>
		<c:set var="click" value="" />
	</c:otherwise>
</c:choose>
	

<tr <%-- onclick="document.location.href='object_edit?id=${id}'" style='cursor:hand;' --%> id="${dif}"
	onmouseover="this.backup=this.style.backgroundColor;this.style.backgroundColor='red';"
	onmouseout="this.style.backgroundColor=this.backup;" >
	<td ${click}><c:out value="${object.id}" />
	</td>
	<td ${click}><c:out value="${object.address}" />
	</td>
	<td ${click}><c:out value="${object.name}" />
	</td>
	<td ${click}><c:out value="${object.surname}" />
	</td>
	<td ${click}><c:out value="${object.patronymic}" />
	</td>
	<td ${click}><c:out value="${object.dateLastRepair}" />
	</td>
	<td ${click}><user:name id="${object.idOwner}" />
	</td>
	<td ${click}>
	<object:task id="${object.id}" />
	</td>
	<td id='l'>
		<c:choose>
		<c:when test="${deletor}">
			<button type="button" onclick="document.location.href='object_edit?id=${object.id}'">edit</button>
			<button type="button" onclick="if (confirm('Уверены?')) document.location.href='object_edit?delete=${object.id}'" style="color:red;">delete</button>
		</c:when>
		<c:when test="${editor}">
			<button type="button" onclick="document.location.href='object_edit?id=${object.id}'">view</button>
		</c:when>
		<c:otherwise>
			только просмотр
		</c:otherwise>
		</c:choose>
	</td>
</tr>